from typing import Annotated
from fastapi import APIRouter, Depends, Query, Request

from models.user import User
from services.user_service import UserService

router = APIRouter()


def get_user_service(request: Request) -> UserService:
    return request.app.state.services.user_service


UserServiceDep = Annotated[UserService, Depends(get_user_service)]


@router.put("/{id}")
def update(id: str, user: User):
    return {
        "id": id,
        "user": user,
    }


@router.get("/details/{id}", response_model=User)
async def get_details(id: str, service: UserServiceDep):
    return service.query_details(id)


@router.get("/avatar")
async def get_avatar(format: Annotated[str | None, Query(min_length=3, title="Query string")], service: UserService = Depends(get_user_service)):
    return {"message": f"This is the user avatar in {format} format."}
